package cn.iocoder.yudao.module.jifenyuan.controller.admin.room;

import cn.iocoder.yudao.module.jifenyuan.controller.app.room.vo.AppRoomExcelVO;
import cn.iocoder.yudao.module.jifenyuan.controller.app.room.vo.AppRoomPageReqVO;
import cn.iocoder.yudao.module.jifenyuan.controller.app.room.vo.AppRoomRespVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.jifenyuan.controller.admin.room.vo.*;
import cn.iocoder.yudao.module.jifenyuan.dal.dataobject.room.RoomDO;
import cn.iocoder.yudao.module.jifenyuan.convert.room.RoomConvert;
import cn.iocoder.yudao.module.jifenyuan.service.room.RoomService;

@Tag(name = "管理后台 - 记分员 房间")
@RestController
@RequestMapping("/jifenyuan/room")
@Validated
public class RoomController {

    @Resource
    private RoomService roomService;

    @PostMapping("/create")
    @Operation(summary = "创建记分员 房间")
    @PreAuthorize("@ss.hasPermission('jifenyuan:room:create')")
    public CommonResult<AppRoomRespVO> createRoom(@Valid @RequestBody RoomCreateReqVO createReqVO) {
        RoomDO room = roomService.createRoom(RoomConvert.INSTANCE.convert(createReqVO));
        AppRoomRespVO convert = RoomConvert.INSTANCE.convert(room);
        return success(convert);
    }

    @PutMapping("/update")
    @Operation(summary = "更新记分员 房间")
    @PreAuthorize("@ss.hasPermission('jifenyuan:room:update')")
    public CommonResult<Boolean> updateRoom(@Valid @RequestBody RoomUpdateReqVO updateReqVO) {
        roomService.updateRoom(RoomConvert.INSTANCE.convert(updateReqVO));
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除记分员 房间")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('jifenyuan:room:delete')")
    public CommonResult<Boolean> deleteRoom(@RequestParam("id") Long id) {
        roomService.deleteRoom(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得记分员 房间")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('jifenyuan:room:query')")
    public CommonResult<AppRoomRespVO> getRoom(@RequestParam("id") Long id) {
        RoomDO room = roomService.getRoom(id);
        return success(RoomConvert.INSTANCE.convert(room));
    }

    @GetMapping("/list")
    @Operation(summary = "获得记分员 房间列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('jifenyuan:room:query')")
    public CommonResult<List<AppRoomRespVO>> getRoomList(@RequestParam("ids") Collection<Long> ids) {
        List<RoomDO> list = roomService.getRoomList(ids);
        return success(RoomConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得记分员 房间分页")
    @PreAuthorize("@ss.hasPermission('jifenyuan:room:query')")
    public CommonResult<PageResult<AppRoomRespVO>> getRoomPage(@Valid AppRoomPageReqVO pageVO) {
        PageResult<RoomDO> pageResult = roomService.getRoomPage(pageVO);
        return success(RoomConvert.INSTANCE.convertPage(pageResult));
    }



}
